package com.sr.demo.security.user;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class NuoUserDetailsService implements UserDetailsService {
    /**
     * 获取用户信息
     * @Author: liushuai
     * @Date: 2021/2/9 18:53
     * @param : * @param userName  用户账号
     * @return :org.springframework.security.core.userdetails.UserDetails
     **/
    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        NuoUser build = NuoUser.builder()
                .id(1L)
                .username("admin")
                .password("$2a$10$CutGBovnt846HK.anJpp2.Kv5crYj4f2rSSo4iLcm962tOeg0SHrG")
                .accountNonExpired(true)
                .accountNonLocked(true)
                .authorities(AuthorityUtils.commaSeparatedStringToAuthorityList("admin"))
                .credentialsNonExpired(true)
                .enabled(true)
                .build();
        return build;
    }
}
